/*
 * @Author: your name
 * @Date: 2024-04-17 11:15:29
 * @LastEditTime: 2024-04-17 11:16:17
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\145.二叉树的后序遍历.cpp
 */
/*
 * @lc app=leetcode.cn id=145 lang=cpp
 *
 * [145] 二叉树的后序遍历
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    void Traversal(TreeNode* cur, vector<int>& vec){
        if(cur != nullptr){
            Traversal(cur->left, vec);
            Traversal(cur->right, vec);
            vec.push_back(cur->val);
        }
    }
    vector<int> postorderTraversal(TreeNode* root) {
        vector<int> res;
        Traversal(root, res);
        return res;
    }
};
// @lc code=end

